package model;

import java.util.LinkedList;
import java.util.List;

import javax.el.ELContext;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;

import data.Local;
import data.Remote;

public class CitySelection {
	private String currentItem;
	private List<SelectItem> allItems;
	private Local localDataset;
	private Remote remoteDataset;

	/**
	 * Constructs the city selector
	 */
	public CitySelection() {
		localDataset = new Local();
		remoteDataset = new Remote();
		List<String> cityResources = localDataset.getCities();

		allItems = new LinkedList<SelectItem>();

		ELContext ctx = FacesContext.getCurrentInstance().getELContext();
		Language language = (Language) ctx.getELResolver().getValue(ctx, null,
				"language");
		String lan = language.getCurrentLanguage();

		for (String cr : cityResources) {
			allItems.add(new SelectItem(cr, remoteDataset.queryCityLabel(cr,
					lan)));
		}
	}

	public String getCurrentItem() {
		return currentItem;
	}

	public void setCurrentItem(String currentItem) {
		this.currentItem = currentItem;
	}

	public List<SelectItem> getAllItems() {
		return allItems;
	}

	public void setAllItems(List<SelectItem> allItems) {
		this.allItems = allItems;
	}
}
